﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using KTVConsole2.Core;

namespace KTVConsole2.UI
{
    /// <summary>
    /// Interaction logic for SavePlayList.xaml
    /// </summary>
    public partial class SavePlayList : Window
    {
        public SavePlayList()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            txtPlayListName.Focus();
            txtPlayListName.Text = DateTime.Now.ToShortDateString();
        }

        private void txtPlayListName_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
                case Key.Enter:
                    btnOk.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));                    
                    break;
            }
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            string input = txtPlayListName.Text.Trim();
            if (input.Length == 0)
            {
                txtPlayListName.Focus();
                return;
            }
            var s = MainWindow.Engine;
            FavoriteSongs fs = new FavoriteSongs();
            fs.Title = input;
            fs.Songs = new System.Collections.ObjectModel.ObservableCollection<Song>(s.PlayList);
            s.MyPlayList.Add(fs);
            s.SaveToXML();
            this.Close();
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
